package  
{
	import fl.containers.ScrollPane;
	import fl.controls.TileList;
	import fl.data.DataProvider;
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.events.Event;
	
	public class mainroom_playerslist extends MovieClip 
	{
		static public const ITEM_HEIGHT:	Number 			= 20;
		
		static public var items:			Array 			= [];
		
		public var symb:					ScrollPane 		= new ScrollPane();
		public var list:					Sprite			= new Sprite();
		
		public function mainroom_playerslist() 
		{
			addEventListener(Event.ADDED_TO_STAGE, init);
		}
		
		private function init(e:Event):void 
		{
			removeEventListener(Event.ADDED_TO_STAGE, init);
			init_list();
			addChild(list);
		}
		
		public function addItem(id:int, username:*= null):void
		{
			//item:mainroom_playerslist_item
			if (!username)
				username = "Гость";
			var newitem:mainroom_playerslist_item = new mainroom_playerslist_item(id, username);
			list.addChild(newitem);
			items.push(newitem)
		}
		
		public function removeItem(index:int):void
		{
			
		}
		
		public function refresh():void
		{
		
		}
		
		public function refresh_players():void 
		{
			for each (var it:mainroom_playerslist_item in items)
			{
				var is_player_finded:Boolean = false;
				for each (var p:Array in mainroom.players) 
				{
					if (p[0] == it.id)
					{
						is_player_finded = true;
						it.update_username(p[1]);
						it.name_symb.y = mainroom.players.indexOf(p) * ITEM_HEIGHT;
					}
				}
				if (!is_player_finded)
				{
					it.destroy();
					delete items[items.indexOf(it)];
				}
			}
		}
		
		private function init_list():void 
		{
			//list.width = 150;
			
		}
		
	}

}